$(function (){
    regi.app.scan();
    regi.app.back();
    regi.app.btn();
});

var regi = {};

regi.app = {};

regi.app.scan = function (){


    $('.div_0 .btn_s').on('touchstart', function (){
        var qr = new QCodeDecoder();
        var btn = $('.btn_s').get(0);
        qr.decodeFromCamera(btn, function (err){
            if(err){
                throw err;
            }

            alert(result);
        });
    });
};
regi.app.back = function (){
    $('header .left').on('touchstart', function (){
        history.back();
    });
};
regi.app.btn = function (){
    var reg = /^1[0-9]{10}$/
    $('.div_4 .btn_y').on('touchstart', function (){
        var val = $('.div_1 .tel').val();
        console.log(val);
        if(reg.test(val)){
        	
        	var token = $("meta[name='_csrf']").attr("content");
       	  	var header = $("meta[name='_csrf_header']").attr("content");
       	 $(document).ajaxSend(function(e, xhr, options) {
       	    xhr.setRequestHeader(header, token);
       	  });

            $.ajax({
                url:'/user/verifycode',
                type:'POST',
                dataType:'json',
                data:{
                    num:val
                },
                success:function (d){
                	alert(d.resultMsg);
                },
                error:function (d){

                }
            });
        }
    });
    
    
    //提交注册信息
    $('.div_3 .btn_z').on('touchstart', function (){
    	 var tui = $('.div_0 .tui').val();
    	 var yan = $('.div_4 .yan').val();
    	 var pass_1 = $('.div_2 .pass_1').val();
    	 
    	var token = $("meta[name='_csrf']").attr("content");
   	  	var header = $("meta[name='_csrf_header']").attr("content");
   	 $(document).ajaxSend(function(e, xhr, options) {
   	    xhr.setRequestHeader(header, token);
   	  });
    	
   	 $.ajax({
         url:'/user/regi',
         type:'POST',
         dataType:'json',
         data:{
             "tui":tui,
             "yan":yan,
             "pass_1":pass_1
         },
         success:function (d){
        	 alert(d.resultMsg);
         },
         error:function (d){

         }
     });
   	 
    
    }); 	
    
}